<?php
$headermsg = '\"HTTP/1.0 '.$code[0].' '.$code[1].'\"';
header($headermsg);
echo "\"photos\":[";
$photocount = 0;
foreach($photodata as $photo){
	if ($photocount != 0){
		echo ",";
	}
	$photocount = 1;
	echo "{\"photo\":{";
	echo "\"id\":\"".$photo['Photo']['id']."\", ";
	echo "\"created\":".$photo['Photo']['created'].", ";
	echo "\"title\":\"".$photo['Photo']['title']."\", ";
	echo "\"width\":\"".$photo['Photo']['width']."\", ";
	echo "\"height\":\"".$photo['Photo']['height']."\", ";
	echo "\"geo_lat\":\"".$photo['Photo']['geo_lat']."\", ";
	echo "\"geo_long\":\"".$photo['Photo']['geo_long']."\", ";
	echo "\"aperture\":\"".$photo['Photo']['aperture']."\", ";
	echo "\"exposuretime\":\"".$photo['Photo']['exposuretime']."\", ";
	echo "\"focallength\":\"".$photo['Photo']['focallength']."\", ";
	echo "\"views\":\"".$photo['Photo']['views']."\", ";
	echo "\"original_filename\":\"".$photo['Photo']['original_filename']."\", ";
	echo "\"user_name\":\"".$photo['Photo']['user_name']."\", ";
	echo "\"upload_complete\":\"".$photo['Photo']['upload_complete']."\", ";
	echo "\"author\":\"".$photo['Photo']['user_id']."\"}";
	
	if(!empty($photodata['Comment'])){
		echo", ";
		$commentcount = 0;
		$comments = $photodata['Comment'];
	
		echo "{\"comments\":[";
		foreach($comments as $comment){
			if ($commentcount != 0){
			echo ",";
			}
			$commentcount = 1;
		echo "{\"comment\":{";
		echo "\"id\":\"".$comment['id']."\",";
		echo "\"photo_id\":\"".$comment['photo_id']."\",";
		echo "\"user_id\":\"".$comment['user_id']."\",";
		echo "\"created\":\"".$comment['created']."\",";
		echo "\"title\":\"".$comment['title']."\",";
		echo "\"comment_text\":\"".$comment['comment_text']."\"}";
		echo "}";
		}
		echo "]}";
	}
	
	if(!empty($photodata['Rating'])){
		echo ", ";
		$ratings = $photodata['Rating'];
		$ratingcount = 0;

		echo "{\"ratings\":[";
		foreach($ratings as $rating){
			if ($ratingcount != 0){
				echo ",";
			}
			$ratingcount = 1;
			echo "{\"rating\":{";
			echo "\"id\":\"".$rating['id']."\", ";
			echo "\"photo_id\":\"".$rating['photo_id']."\", ";
			echo "\"user_id\":\"".$rating['user_id']."\", ";
			echo "\"value\":\"".$rating['value']."\"}";
			echo "}";
		}
		echo "]}";
		echo ",";
	}
	
	if (!empty($photo['Tag'])){
		echo ", ";
		$tags = $photo['Tag'];
		$tagcount = 0;
		
		echo "{\"tags\":[";
		foreach($tags as $tag){
			if($tagcount != 0){
				echo ",";
			}
			$tagcount = 1;
			echo "{\"tag\":{";
			echo "\"id\":\"".$tag['id']."\", ";
			echo "\"photo_id\":\"".$tag['photo_id']."\", ";
			echo "\"tag_tame\":\"".$tag['tag_name']."\"}";
			echo "}";
		}
		echo "]}";
	}
	
	echo ", ";
	echo "\"description\":\"".$photo['Photo']['description'];
	echo "}";
}
echo "]}";
?>